<?php

namespace app\admin\controller\order;

use app\admin\controller\goods\Goods;
use app\admin\model\Delivaddress;
use app\admin\model\goods\GoodsItem;
use app\admin\model\order\OrderGoods;
use app\common\controller\Backend;
use Monolog\Handler\IFTTTHandler;
use think\Db;
use think\Validate;
use wxpay\Delivery;
use app\admin\model\order\Order as OrderModel;
use app\admin\model\order\Sale as SaleModel;
use function GuzzleHttp\Psr7\str;

/**
 * 订单管理
 *
 * @icon fa fa-circle-o
 */
class Order extends Backend
{

    /**
     * Order模型对象
     * @var \app\admin\model\order\Order
     */
    protected $model = null;
    protected $noNeedRight = ['*'];
    protected $noNeedLogin = ['*'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\order\Order;
        $this->OrderGoodsmodel = new \app\admin\model\order\OrderGoods;
        $this->view->assign("deliveryList", $this->model->getDeliverylist());
        $this->view->assign("orderStatusList", $this->model->getOrderStatusList());
        $this->view->assign("payStatusList", $this->model->getPayStatusList());
        $this->view->assign("payWayList", $this->model->getPayWayList());
        $this->view->assign("refundStatusList", $this->model->getRefundStatusList());
        $this->view->assign("shippingStatusList", $this->model->getShippingStatusList());
    }


    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);

        $page    = $this->request->param('page', 1);
        $status  = $this->request->param('status', 0);


        $goodsId = $this->request->param('goodsId');
        $goodsName   = $this->request->param('goodsName');
        $goodsNumber = $this->request->param('goodsNumber');
        $uid = $this->request->param('uid','');
        $name  = $this->request->param('name');
        $phone = $this->request->param('phone');
        $orderNumber = $this->request->param('orderNumber');
        $createtime  = $this->request->param('createtime');
        $endtime     = $this->request->param('endtime');

        $where = [];
        if (!empty($createtime) && !empty($endtime))
        {
            $where['create_time'] = ['>', strtotime($createtime)];
            $where['end_time']    = ['<', strtotime($endtime)];
        }elseif(!empty($createtime))
        {
            $where['create_time'] = ['>', strtotime($createtime)];
        }elseif (!empty($endtime)){
            $where['end_time'] = ['<', strtotime($endtime)];
        }

        if (!empty($uid))
        {
            $where['uid'] = ['eq',$uid];
        }

        if (!empty($name))
        {
            $where['name'] = ['like','%'.$name.'%'];
        }

        if (!empty($phone))
        {
            $where['mobile'] = ['like','%'.$phone.'%'];
        }

        if (!empty($orderNumber))
        {
            $where['order_sn'] = ['like','%'.$orderNumber.'%'];
        }
        if ($status == 4)
        {
            $where['order_status'] = [
                ['=',$status],['=',3],'or'
            ];
        }
        elseif ($status == 5){
            $where['pay_status']   = [['eq',1],['=',3],['=',2],"or"];
            $where['order_status'] = ['eq', $status];
        }
        else{
            $where['order_status'] = ['eq', $status];
        }

        $row = $this->model
            ->with(['orderGoods' => function($query) use($goodsName ,$goodsNumber ,$goodsId ){
                if (!empty($goodsName) && !empty($goodsNumber) && !empty($goodsId))
                {
                    $query->where('goods_name','like','%'.$goodsName.'%')
                        ->where('name_keyword','like','%'.$goodsNumber.'%')
                        ->where('goods_id','eq',$goodsId);
                }elseif ($goodsName){
                    $query->where('goods_name','like','%'.$goodsName.'%');
                }elseif ($goodsNumber){
                    $query->where('name_keyword','like','%'.$goodsNumber.'%');
                }elseif ($goodsId) {
                    $query->where('name_keyword','eq',$goodsId);
                }
            }])
            ->where($where)
            ->order('id desc')
            ->paginate(10, false, [
                'page'  => $page,
                'query' => [
                    'status'  => $status,
                    'goodsId' => $goodsId,
                    'goodsName'  => $goodsName,
                    'goodsNumber' => $goodsNumber,
                    'name'  => $name,
                    'phone' => $phone,
                    'orderNumber'=> $orderNumber,
                    'createtime' => $createtime,
                    'endtime'    => $endtime,
                    'uid'   => $uid
                ]
            ]);


        $list = $row->toArray();

        $list = $list['data'];
        foreach ($list as $key => $val) {
            foreach ($val['order_goods'] as $k => $v) {
                    if ($val['order_status'] <= 4 )
                    {
                        if ($v['refund_status'] != 0)
                        {
                            unset($list[$key]['order_goods'][$k]);
                            continue;
                        }
                    }elseif ($val['order_status'] == 5) {

                        if ($v['refund_status'] == 0)
                        {
                            unset($list[$key]['order_goods'][$k]);
                            continue;
                        }
                    }elseif ($val['order_status'] == 6) {
                        // if ($v['refund_status'] != 4)
                        if ($v['refund_status'] == 0 || $v['refund_status'] == 1 || $v['refund_status'] == 2 || $v['refund_status'] == 5)
                        {
                            unset($list[$key]['order_goods'][$k]);
                            continue;
                        }
                    }
                        if ($v['sku_id'] == 0) {
                            $specName = '无';
                        } else {
                            $spec = GoodsItem::where('id', $v['sku_id'])->value('spec');
                            if($spec){
                                $spec = json_decode($spec, true);
                                $specName = '';
                                foreach ($spec as $specKey => $sepecVal) {
                                    $specName .= ',' . $sepecVal['name'] . ':' . $sepecVal['value'];
                                }
                                $specName = substr($specName, 1);
                            }else{
                                $specName = '无';
                            }
                            
                        }
                        $list[$key]['order_goods'][$k]['sku_name'] = $specName;

            }
        }

        foreach ($list as $k => $v)
        {
            if(empty($v['order_goods']))
                unset($list[$k]);
        }

        $params = [
            'goodsId' => $goodsId,
            'goodsName' => $goodsName,
            'goodsNumber' => $goodsNumber,
            'name' => $name,
            'phone' => $phone,
            'orderNumber' => $orderNumber,
            'createtime' => $createtime,
            'endtime' => $endtime,
        ];


        $this->view->assign('params',$params);
        $this->view->assign('row', $row);
        $this->view->assign('status', $status);
        $this->view->assign('list', $list);
        $this->view->assign('uid', $uid);
        $this->view->assign('total', $this->model->count());
        return $this->view->fetch();

    }

    public function show($ids = '')
    {
        if ($ids == null) $this->error('参数错误');
        $status = $this->request->param('status','');
        $order = $this->model
            ->with('userone')
            ->where('id', $ids)
            ->find();

        if (!$order) $this->error('参数错误');
        $is_shop = $order->is_shop;

        if ($is_shop) {
            $shopname = $this->model->getShop($is_shop);
            $order->shop_name = $shopname;
        }

        if ($order->collocation_id) {
            $order->collocation_id = $this->model->getcollocation($order->collocation_id);
        } else {
            $order->collocation_id = '无';
        }
        $OrderGoods = $this->OrderGoodsmodel->getOrdergoods($ids,$status,'refund');

        $this->assign('OrderGoodsList', $OrderGoods);
        $this->assign('row', $order);
        return $this->fetch();
    }

    /**
     * @param string $ids
     * 手动发货
     */
    public function delivery($ids = '')
    {
        $order = $this->model->get($ids);

        $admin_id = $this->auth->id;
        if (empty($order)) $this->error('订单信息不存在');
        if (empty($order['delivery_type'])) $this->error('请选择快递付款方式');
        if (empty($order['deliv_address'])) $this->error('请添加发货地址');

            $params = $this->request->param();
            if (empty($params['delivery_name'])) $this->error('请填写快递单号');

            $validate = new Validate([
                'delivery_name|快递公司' => 'require|max:50',
                'delivery_id|快递单号' => 'require|max:50',
            ]);

            if (!$validate->check($params)) {
                $this->error($validate->getError());
            }
            $time = time();

            $day = Db::name('config')
                ->where('name', 'goods_day')
                ->where('group', 'basic')
                ->value('value');
            $num_time = 60 * 60 * 24 * $day;

            $end_time = $time + $num_time;
            $data = [
                'order_status' => 2,
                'shipping_status' => 1,
                'shipping_time' => $time,
                'end_time' => $end_time,
                'update_time' => $time,
                'delivery_name' => $params['delivery_name'],
                'delivery_id' => $params['delivery_id'],
            ];
            $response = $this->model->save($data, ['id' => $ids, 'order_status' => 1]);

            if ($response) {
                $delivaddresslist = Delivaddress::get($order['deliv_address']);
                // 添加快递记录
                Db::name('courier')->insertGetId([
                    'orderid' => $ids,
                    'order_pay_sn' => $order['order_sn'],
                    'name'    => '手动发货',
                    'country'     => 'ZH',
                    'province'  => $delivaddresslist['province'],
                    'city'      => $delivaddresslist['city'],
                    "tel"       => $delivaddresslist['phone'],
                    'county'    => $delivaddresslist['area'],
                    'address'   => $delivaddresslist['address'],
                    'admin_id'  => $admin_id,
                    'waybill'   => $params['delivery_id'],
                    'filterResult'   => 1,
                    'remark'    => '手动发货',
                    'createtime'     => $time,
                    'filterStatus'   => 1,
                    'filtertime'     => $time,
                    'opcodeRemak'    => '手动发货',
                ]);
                $this->system($ids);
                $this->success('发货成功');
            } else {
                $orderGoods = Db::name('order_goods')
                    ->where('order_id', $ids)
                    ->select();
                $title = '';
                foreach ($orderGoods as $key => $val) {
                    $title .= '|' . $val['goods_name'];
                }
                if ($order['order_status'] > 1) {
                    $this->error('该订单已发货');
                }
                if ($order['order_status'] == 0) {
                    $this->error('该订单暂未支付');
                }
                $this->error('操作失败');
            }

    }

    /**
     * 延长收货时间
     * @param string $ids
     * @return mixed
     */
    public function extended($ids = "")
    {

        if ($this->request->isPost()) {
            $params = $this->request->param('row/a');
            $day = $params['day_time'];

            if (empty($day) || empty($ids)) $this->error('缺少参数');

            $validate = new Validate([
                'day_time' => 'require|number'
            ]);

            if (!$validate->check($params)) {
                $this->error($validate->getError());
            }
            $time = time();
            $end_time = Db::name('order')->where('id', $ids)->value('end_time');
            $day_time = 60 * 60 * 24 * $params['day_time'];
            $end_day_time = $end_time + $day_time;
            $data = [
                'update_time' => $time,
                'day_time' => $params['day_time'],
                'end_time' => $end_day_time
            ];

            $response = $this->model->save($data, ['id' => $ids]);

            if (!$response) $this->error('延长失败');

            $this->success();
        }
        return $this->fetch();
    }

    /**
     * 发送快递
     */
    public function autodelivery($ids = "")
    {
        $order = OrderModel::get($ids);
        if (empty($ids)) {
            $this->error('请选择发货订单');
        }
        if (!$order) {
            $this->error('订单信息不存在');
        }

        if ($order['order_status'] == 0 && $order['pay_status'] == 0) {
            $this->error('订单未支付');
        }
        if (false === $this->request->isPost()) {

            $deliveryaddress = Db::name('delivaddress')->where('deletetime',0)->select();
            $array = [
                'id' => 0,
                'province' => '',
                'city' => '',
                'area' => '',
                'address' => '无任何选择'
            ];
            array_unshift($deliveryaddress,$array);

            $OrderGoods = $this->OrderGoodsmodel->getOrdergoods($ids);
            $order['deliveryaddress'] = Db::name('delivaddress')->where('id',$order['deliv_address'])->find();
            $order['refundaddress']   = Db::name('delivaddress')->where('id',$order['refund_address'])->find();
            $delivery_express_list = Db::name('delivery_express')->where('is_delete',0)->select();
            $this->view->assign('row', $order);
            $this->view->assign('delivery_express_list', $delivery_express_list);
            $this->view->assign('deliveryaddress', $deliveryaddress);
            $this->view->assign('OrderGoods', $OrderGoods);
            return $this->view->fetch();
        }
        if ($order['shipping_status'] != 0) {
            $this->error('订单已发货,请勿重复操作');
        }

        if (empty($order['deliv_address'])) $this->error('请设置发货地址');
        if (empty($order['delivery_type'])) $this->error('请选择运费方式');

        $delivaddressinfo = Delivaddress::get($order['deliv_address']);
        if (empty($delivaddressinfo)) $this->error('信息不存在,请从新上传发货地址');
        $admin_id = $this->auth->id;
        if (empty($admin_id)) {
            $this->success('请先进行登录操作');
        }

        if (empty($delivaddressinfo['name']) || empty($delivaddressinfo['phone']) || empty($delivaddressinfo['province']) || empty($delivaddressinfo['city']) || empty($delivaddressinfo['address']) )
        {
            $this->error('请补全发货信息');
        }

        $delivery = new Delivery();
        $courierList = Db::name('courier')->where('orderid', $ids)->find();

        if (empty($courierList)) {
            $courier = [
                'company' => $delivaddressinfo['company'],
                'tel'     => $delivaddressinfo['phone'],
                'name'    => $delivaddressinfo['name'],
                'province'=> $delivaddressinfo['province'],
                'city'    => empty($delivaddressinfo['city']) ? '' : $delivaddressinfo['city'],
                'county'  => empty($delivaddressinfo['area']) ? '' : $delivaddressinfo['area'],
                'address' => $delivaddressinfo['address'],
            ];

            $courier['orderid'] = $ids;
            $courier['order_pay_sn'] = $order['order_sn'];
            $courier['createtime'] = time();
            $courier_id = Db::name('courier')->insertGetId($courier);
        } else {

            $courier_id = $courierList['id'];
        }

        $data = $delivery->placeOrder($order, $courier_id, $admin_id,$order['delivery_type']);

        if ($data['status'] == true && $this->system($ids))
        {
            $this->success('发货成功');
        } else {

            $this->error($data['msg']);
        }
    }


    /**
     * 快递发送消息
     */
    public function system($ids,$type=0)
    {
        $where = [];
        $where['order_id']      = ['eq',$ids];

        $orderGoods = Db::name('order_goods')
            ->where($where)
            ->select();
        $user_id = Db::name('order')
            ->where('id', $ids)
            ->value('uid');

        $title = '';
        $goods_image = '';
        foreach ($orderGoods as $key => $val) {
            $title .= '|' . $val['goods_name'];
            $goods_image .= '|' . $val['goods_image'];
        }

        $goods_image = substr($goods_image, 1);

        if ($type == 1)
        {
            $title = '商家已关闭订单'.$title;
        }else{
            $title = '您购买的' . $title . '已经发货';
        }

        $data = [
            'admin_id' => $this->auth->id,
            'uid' => $user_id,
            'order_id' => $ids,
            'name' => $title,
            'goods_image' => $goods_image,
            'create_time' => time()
        ];
        $orderId = Db::name('system_order')->insertGetId($data);
        return $orderId;
    }


    /**
     * 查询快递
     */
    public function orderquery($ids = '')
    {
        if (empty($ids)) {
            $this->error('请选择查询数据');
        }
        $orderData = $this->model->get($ids);
        if (empty($orderData)) {
            $this->error('快递信息不存在,请核对订单信息');
        }
        if ($this->request->isAjax()) {
            $Delivery = new Delivery();
            $response = $Delivery->courierQuery($orderData);
            if ($response['status'] == true) {
                $this->success($response['msg']);
            } else {
                $this->error($response['msg']);
            }
        }

    }

    /**
     * 获取退款信息
     */
    public function refund()
    {
        $goodsId = $this->request->param('goodsId');
        $orderData = Db::name('order_sale')
            ->where('order_goods_id', $goodsId)
            ->find();

        return json($orderData);
    }

    /**
     * 关闭订单
     */
    public function orderShut()
    {
        $id = $this->request->param('id');

        if (empty($id))
        {
            $this->error('缺少参数');
        }
        $orderData = $this->model->get($id);
        if (empty($orderData))
        {
            $this->error('订单信息不存在');
        }
        if ($orderData['order_status'] == 6 && $orderData['pay_status'] == 2)
        {
            $this->success('订单已退款无需重复操作');
        }

        if ($orderData['order_status'] == 0 && $orderData['pay_status'] == 0)
        {
            $orderData->order_status = 6;
            $orderData->update_time  = time();
            $orderData->save();
            OrderGoods::where('order_id',$orderData['id'])
                ->where('refund_status',0)
                ->update(['refund_status' => 4]);
            $this->success('操作成功');
        }

        if ($orderData['user_status'] < 2)
        {
             $response = $this->model->money($orderData);
        }else{
            $response = $this->model->integral($orderData);
        }

        if ($response['status'] == true)
        {

            $orderData->order_status = 6;
            $orderData->save();
            OrderGoods::where('order_id',$orderData['id'])
                ->where('refund_status',0)
                ->update(['refund_status' => 4]);
            $this->system($orderData['id'],1);
            $this->success($response['msg']);
        }else{
            $this->error($response['msg']);
        }
    }

    /**
     * 关闭单个商品
     */
    public function orderGoodsshut()
    {
        $id = $this->request->param('id');
        if (empty($id))
        {
            $this->error('缺少参数','order/order/index');
        }
        $orderGoods = OrderGoods::get($id);
        if (empty($orderGoods))
        {
            $this->error('订单信息不存在','order/order/index');
        }

        if ($orderGoods['is_comment'] == 3)
        {
            $this->error('该商品已退款','order/order/index');
        }

        $orderData = OrderModel::get($orderGoods['order_id']);

        if ($orderData['pay_status'] == 0)
        {
            OrderGoods::where('id',$id)->update([
                'refund_status' => 4
            ]);
            $orderGoodsnum = OrderGoods::where('order_id',$orderData['id'])
                ->where('refund_status',0)
                ->count();
            if ($orderGoodsnum <= 0)
            {
                OrderModel::where('id',$orderData['id'])->delete();
            }
            $this->success('操作成功','order/order/index');
        }

        if ($orderData['user_status'] < 2)
        {
            $response = $this->model->goodsMoney($id);
        }else{
            // 退积分
            $response = $this->model->goodsIntegral($id);
        }

        if ($response['status'] == true)
        {
            OrderGoods::where('id',$id)->update([
                'refund_status' => 4
            ]);
            $data = [
                'admin_id' => $this->auth->id,
                'uid' => $orderData['uid'],
                'order_id' => $orderData['id'],
                'name' => '关闭订单'.$orderGoods['goods_name'],
                'goods_image' => $orderGoods['goods_image'],
                'create_time' => time()
            ];
            $orderId = Db::name('system_order')->insertGetId($data);

            $this->success($response['msg'],'order/order/index');
        }else{
            $this->error($response['msg'],'order/order/index');
        }
    }

    /**
     * 修改地址
     */
    public function userAddress()
    {
        if (!$this->request->isAjax())
        {
            $this->error('请从新提交操作');
        }

        $params = $this->request->param();


        if (empty($params['id']) || empty($params['region']) || empty($params['address']))
        {
            $this->error('缺少参数');
        }

        $order = $this->model->get($params['id']);

        if (empty($order))
        {
            $this->error('订单信息不存在');
        }

        if ($order['order_status'] == 2 || $order['shipping_status'] == 1)
        {
            $this->error('订单已发货无法修改');
        }



        $region = explode('/',$params['region']);
        if (!empty($params['phone']) && preg_match("/^1[34578]\d{9}$/",$params['phone']))
        {
            $order->mobile = $params['phone'];
        }

        if (!empty($params['name']))
        {
            $order->name = $params['name'];
        }
        $order->province = $region[0];
        $order->city     = empty($region[1]) ? '' : $region[1];
        $order->district = empty($region[2]) ? '' : $region[2];
        $order->address  = $params['address'];
        $order->update_time  = time();
        $order->save();

        if ($order->id)
        {
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }

    }

    /**
     * 修改订单价格
     */
    public function userprice()
    {

        $id = $this->request->param('id');
        $row = $this->model->get($id);
        if (empty($row)) $this->error('订单信息不存在');
        if (false == $this->request->isPost())
        {
            $this->view->assign('row',$row);
            return $this->view->fetch();
        }
        $params = $this->request->param('row/a');
        $row->goods_pay_price = $params['goods_pay_price'];
        $row->save();
        $this->success('操作成功');
    }

    /**
     * 设置收发货地址
     */
    public function addressadd()
    {
        $this->request->param();
    }

    /**
     * 获取收货信息
     */
    public function getaddress()
    {
        $ids = $this->request->param('ids','');
        $company = $this->request->param('company','');  // 公司名
        $name = $this->request->param('name','');       //发货人
        $phone = $this->request->param('phone','');     //联系电话
        $native = $this->request->param('native','');   //省市区
        $address = $this->request->param('address',''); // 详细地址
        $orderid = $this->request->param('orderid');
        $status = $this->request->param('status');
        if (!empty($ids))
        {
            if (empty($ids)) $this->error('缺少参数');
            $delivaddress = Delivaddress::get($ids);
            if (empty($delivaddress)) $this->error('信息不存在请从新选择');
            if (!empty($company) || !empty($name) || !empty($phone) || !empty($native) || $address)
            {
                if ($company) $delivaddress->company = $company;
                if ($name) $delivaddress->name = $name;
                if ($phone) $delivaddress->phone = $phone;

                if ($native){
                    $accept_native_place = explode('/', $native);
                    $delivaddress->province = $accept_native_place[0];
                    $delivaddress->city = empty($accept_native_place[1]) ? '' : $accept_native_place[1];
                    $delivaddress->area = empty($accept_native_place[2]) ? '' : $accept_native_place[2];
                }
                if ($address){
                    $delivaddress->address = $address;
                }
                $delivaddress->save();
                $delivaddress = Db::name('delivaddress')->where('id',$ids)->find();
            }
        }else{
            if (empty($company) || empty($name) || empty($phone) || empty($native) || empty($address))
            {
                $data = [
                    'code' => 2,
                    'msg'  => '请完善地址信息'
                ];
                return json($data);
            }

            $accept_native_place = explode('/', $native);
            $delivaddress = [
                'company' => $company,
                'name' => $name,
                'phone' => $phone,
                'province' => $accept_native_place[0],
                'city' => empty($accept_native_place[1]) ? '' : $accept_native_place[1],
                'area' => empty($accept_native_place[2]) ? '' : $accept_native_place[2],
                'address' => $address
            ];
            $ids = Db::name('delivaddress')->insertGetId($delivaddress);
        }

        if ($status == 1)
        {
            $updata = [
                'deliv_address' => $ids
            ];
        }else{
            $updata = [
                'refund_address' => $ids
            ];
        }

        Db::name('order')->where('id',$orderid)->update($updata);
        $data = [
            'code' => 1,
            'msg'  => '操作成功',
            'data' => $delivaddress,
            'url'  => '',
            'wait' => 3
        ];

        return json($data);
    }


    public function deliveltype()
    {
        $id = $this->request->param('ids');
        $type = $this->request->param('type');
        $order = $this->model->get($id);

        if (empty($order)) $this->error('订单信息不存在');

        if ($order['order_status'] >= 2) $this->error('订单已发货无法修改');

        $order->delivery_type = $type;
        $order->save();

        $this->success('1','操作成功',$order);
    }
    /**
     * 同意退款
     */
    public function refundtui()
    {
        $ids = $this->request->param("ids");
        if (!$ids) $this->error('参数不能为空');
        // dump($ids);
        // die;
        // $row   = $this->model->get($ids);
        $row = SaleModel::where("order_id",$ids)->find();
        if (!$row) $this->error('退款信息不存在');

        $orderData = OrderModel::where('id',$row['order_id'])->find();
        $orderGoods = OrderGoods::where('id',$row['order_goods_id'])->find();
        $OrderModel = new OrderModel();

        if ($orderData['user_status'] < 2)
        {
            $response = $OrderModel->goodsMoney($orderGoods['id']);
        }else{
            $response = $OrderModel->goodsIntegral($orderGoods['id']);
        }

        if ($response['status'] == true)
        {
            $time = time();
            $row->status = 6;
            $row->update_time = $time;
            $row->save();
            $this->success($response['msg'],'order/order/index');
        }else{
            $this->error($response['msg'],'order/order/index');
        }
    }
    //拒绝退款
    public function refundjujue(){
        $ids = $this->request->param("ids");
        
        if (!$ids)
        {
            $this->error('参数不能为空','order/order/index');
        }
        // $params = $this->request->param();
        $row = SaleModel::where("order_id",$ids)->find();
        if (!$row)
        {
            $this->error('数据不存在','order/order/index');
        }
        $ordergoods = OrderGoods::get($row['order_goods_id']);
        $ordergoods->refund_status = 5;
        OrderModel::where('id',$row['order_id'])->update(['pay_status' => 3]);
        $ordergoods->save();
        $row->status = 1;
        $row->save();
        $this->success('操作成功','order/order/index');
    }
}
